<?php
/*计算机考试，会计考试查询成绩*/
namespace Common\Org;
class ExamQuery
{
     public $cookie_file;
					 public function __construct(){
							 $this->cookie_file="ExamQuery_array_computer.tmp";
								$this->cookie_file_accountancy="ExamQuery_array_accountancy.tmp";
					}
					//计算机考试采集查询参数
					function computerHtml($reload="0"){
						 $_GET['SCRIPT_ROOT']="";
						 $array_computer=S('ExamQuery_array_computer');
							if($array_computer && $reload!="reload") {
								return  $array_computer;
							}
						 $array_computer=array();
							header("Content-type: text/html; charset=utf-8");
								$url="http://query.neea.edu.cn/examcenter/query.cn?op=doQueryCond&sid=300&pram=results";
								$content=mycurl($url,"",$this->cookie_file,1);
								//dump($content);
							 $phpQuery=new \Common\Org\JAE\QueryList();
								$hobj = \phpQuery::newDocumentHTML($content);
								$robj = pq($hobj)->find("[name='ksnf']")->find("option");
								foreach($robj as $one){//考试时间
									  $array_computer['ksnf'][]=array(
											 'value'=>pq($one)->attr("value"),
												'text'=>pq($one)->text(),
											);
								}
																
								$robj = pq($hobj)->find("[name='bkjb']")->find("option");
								foreach($robj as $one){//报考级别
									  $array_computer['bkjb'][]=array(
											 'value'=>pq($one)->attr("value"),
												'text'=>pq($one)->text(),
											);
								}
								
								foreach($array_computer['ksnf'] as $one){ //选择报考省份
								  $url="http://query.neea.edu.cn/examcenter/querydata.cn?op=doQuerySF&examid=".$one['value'];
										$sfcontent=json_decode(mycurl($url),true);
										$array_computer['sf'][$one['value']]=$sfcontent;
								}
								S('ExamQuery_array_computer',$array_computer);
								return $array_computer;
					}
					//计算机验证码
					function computerHtmlImage(){
								 mycurl("http://query.neea.edu.cn/examcenter/query.cn?op=doQueryCond&sid=300&pram=results","",$this->cookie_file,1);
									$url="http://query.neea.edu.cn/examcenter/myimage.jsp";
									$content=mycurl($url,$postData,$this->cookie_file);
									$img=base64_encode($content);
									return $img;
					}
					//查询计算机
					function computerSearch($postData){
						  //$postData['sf']="13";
							//	$postData['bkjb']="15";
								//$postData['rand']="y8jm";
								//dump($postData);
					   $url="http://query.neea.edu.cn/examcenter/query.cn?op=doQueryResults";
								$content=mycurl($url,$postData,$this->cookie_file);
								$phpQuery=new \Common\Org\JAE\QueryList();
								$hobj = \phpQuery::newDocumentHTML($content);
								$text=pq($hobj)->find("#all")->text();
								header("Content-type: text/html; charset=utf-8");
								if($text){
								   $return=array(
										   'error'=>1,
													'msg'=>trim($text),
										);	
								}else{
									  $info=array();
									  $he_xi=pq($hobj)->find(".he_xi");	
											foreach($he_xi as $one){
													$info[trim(trim(pq($one)->text()),"：")]=trim(pq($one)->next()->text());
											}
									  $return=array(
										   'error'=>0,
													'msg'=>$info,
										);	
								}
								return $return;
								//dump($return);
					}
   
					//查询会计
						function accountancySearch($postData){
								header("Content-type: text/html; charset=utf-8");
							  $area_id=110000;//北京
									$url=$this->getAccountancyUrl($area_id);
									if($url['error']!=0) return $url;
									$url=$url['msg'];
								 $params=$this->getAccountancyPostData($area_id);
									if($params['error']!=0) return $params;
									$post=array();
									$postData['name']=iconv('UTF-8', 'GB2312//IGNORE', $postData['name']);
									foreach($params['msg'] as $k=>$one){
										  $post[$one]=$postData[$k];
									}	
									$write=1; 
									if($postData['accountancy_type'] == 2){
										 $post=array('dyzm'=>$postData);
											$write=0;
									}
								 $content=mycurl($url['post'],http_build_query($post),$this->cookie_file_accountancy,$write);
									$data=$this->getAccountancyData($content);
																	
									return $data;
						}
						//不同地区不同表单会计查询的
						function getAccountancyPostData($area){
							  $arr=array('110000'=>array('cid'=>'KJ_KSCJXX/CID','name'=>'KJ_KSCJXX/PNAME','phone'=>'KJ_KSPHONE/PHONENM'));
										if($arr[$area]){
											  return array('error'=>0,'msg'=>$arr[$area]);
										}else{
											 return array('error'=>1,'msg'=>'当前地区暂时没配置参数');
										}
						}
						
						function getAccountancyUrl($area){//不同省份不同url
						   $arr=array(
									   '110000'=>array(
																'query'=>'http://kjks.bjcz.gov.cn/cjcx/page/cjcxlogin.jsp',
																'post'=>'http://kjks.bjcz.gov.cn/cjcx/page/cjcx.pr.prcjcxdl_CJQuery.do',
																'post2'=>'http://kjks.bjcz.gov.cn/cjcx/page/cjcx.pr.prcjcx_CJQuery.do',
												),
									 );
										if($arr[$area]){
											  return array('error'=>0,'msg'=>$arr[$area]);
										}else{
											 return array('error'=>1,'msg'=>'当前地区暂时没开通');
										}
							
						}
						
						function getAccountancyData($content){//不同省份不同html
						   $content=iconv('GB2312', 'UTF-8//IGNORE', $content);
									$phpQuery=new \Common\Org\JAE\QueryList();
								 $hobj = \phpQuery::newDocumentHTML($content);
								 $sendmsg=pq($hobj)->find("#sendmsg")->length;
									$table=pq($hobj)->find("table")->eq(1)->find("td:eq(3)")->length;
									if($sendmsg){
										  return array('error'=>0,'msg'=>"短信验证码发送成功");
									}else if($table){
										  $msg=pq($hobj)->find("table")->eq(1)->find("td:eq(3)")->text();
												return array('error'=>1,'msg'=>trim($msg));
									}else{
												return array('error'=>1,'msg'=>$content);
									}
							  
									
						}
					
			

}
 